// pages/code/code.js
const request = require('../../utils/request.js');
const app = getApp()
let drawQrcode = require("../../utils/weapp-qrcode.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: "",
    flag: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  refresh: function () {
    var info = wx.getStorageSync('userInfo');
    var data;
    if (this.data.flag == true) {
      data = {
        accessNum: info.accessNum,
        id: info.id,
        name: info.name,
        roomNumber: info.roomNumber,
        idCard: info.idCard,
        avatarUrl:info.avatarUrl,
      }
      this.data.flag=false;
    }else{
      data = {
        id: info.id,
        name: info.name,
        roomNumber: info.roomNumber,
        idCard: info.idCard,
        accessNum: info.accessNum,
        avatarUrl:info.avatarUrl,
      }
      this.data.flag=true;
    }
    this.draw(data);
  },
  draw: function (data) {
    var d = JSON.stringify(data);
    drawQrcode({
      width: 200,
      height: 200,
      canvasId: 'myQrcode',
      // ctx: wx.createCanvasContext('myQrcode'),
      text: d,
      image: {
        imageResource: "../../images/Icon_3.png",
        dx: 80,
        dy: 80,
        dWidth: 40,
        dHeight: 40
      },
      // v1.0.0+版本支持在二维码上绘制图片
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var info = wx.getStorageSync('userInfo');
    console.log(info);
    var data = {
      id: info.id,
      name: info.name,
      roomNumber: info.roomNumber,
      idCard: info.idCard,
      accessNum: info.accessNum,
      avatarUrl:info.avatarUrl,
    }
    this.draw(data);
    //请求个人数据
    // wx.request({
    //   url: 'http://47.106.183.53:9090/wx/user',
    //   method:'GET',
    //   // responseType:'arraybuffer',
    //   encoding:null,
    //   header:{
    //     token:info.token,
    //     'content-type': 'application/x-www-form-urlencoded'
    //   },
    //   success:function(e){
    //     console.log(e);
    //   }
    // })
    // this.setData({
    //   url:'iVBORw0KGgoAAAANSUhEUgAAASwAAAEsAQAAAABRBrPYAAAHU0lEQVR42u2aT26DTBbEH2LRO3MBJK7RO64EFzBwAbgSu74GEheAHQtEz6/IyM63GGlGojWbRJH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P5t6kdWJKWBUcn47cMww7hTFXzkbfc3z9y9X8ygs3oQJJyMQ1B5VhyIQJV3Sve+VZgIYbIkhx11AF9pC6/7R6fIxU4LKXzbvSZikFidTx9upQiky5ya21I6iiElgOlJEcPVPJhgMXZMpC4zP52+n+jis8dL36TZOYw1RaxfU+x+TnAr2rsWQImd/+/OgK6qoQK1DGhhZmLR/hi7OYv5pMeSJvFDtZ5sGpno78KU074rz3xV/GGwxjGv8Logehf39p98f7A/2/4L9C4mTr3IMj5hlAAAAAElFTkSuQmCC',
    // })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})